﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net.Sockets;
using System.Runtime.InteropServices.ComTypes;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Org.BouncyCastle.Bcpg;
using 文华财经数据解析_donet8_.entity;

namespace 文华财经数据解析_donet8_.utils.WHDataServer
{
    delegate void RspDayKLine(int allNum, int currNum, List<KlineData> kLines, ushort ReqID);


    internal class WHServer
    {

        public RspDayKLine OnRspDayKLine;

        private string server = "60.190.146.136";
        private int port = 8200;
        TcpClient client;
        NetworkStream stream;

        object lockSend=new object();
        public WHServer(byte[] catchData) 
        {
            client = new TcpClient(server, port);
            stream=client.GetStream();
            //登陆操作
            LoginOption(catchData);
            StartRecive();
            

        }
        void StartRecive() 
        {
            Task.Run(() => {
                PacketParse packetParse = new PacketParse();
                byte[] data=new byte[1024];
                while (true)
                {
                    int bytesRead = stream.Read(data, 0, data.Length);
                    
                    packetParse.Recive(data, 0, bytesRead);
                    while (true)
                    {
                        var pack = packetParse.push();
                        if (pack==null)
                        {
                            break;
                        }
                        else
                        {
                            //Console.WriteLine($"接收到数据包包头为{pack[0]} {pack[1]}");
                            //处理pack
                            if (pack[0] == 0x3a && pack[1]==0xe6&& pack[4] == 0x02 && pack[5]==0x42)
                            {
                                ParseRspDayKline(pack);
                            }
                            //处理登陆请求
                            if (pack[0] == 0x3a && pack[1] == 0xe6 && pack[4] == 0x08 && pack[5] == 0x41)
                            {
                                ParseRspLogin(pack);
                            }
                            //处理登陆验证包
                            if (pack[0] == 0x3a && pack[1] == 0x6c && pack[2] == 0x15 && pack[3] == 0x42)
                            {
                                ParseRspLoginYZ(pack);
                            }
                        }
                    }
                }
            
            });

            
        }

        private void ParseRspLoginYZ(byte[] pack)
        {
            //验证返回
            // 建立保活线程
            Task.Run(() => {
                while (true)
                {
                    Thread.Sleep(1000);
                    byte[] sendData = {
                    0x3a, 0x6c, 0xb9, 0x02, 0x00, 0xbf, 0x00, 0x00
            
                    };
                    sendDatas(sendData);
                    
                }
            
            });
        }

        private void ParseRspLogin(byte[] pack)
        {
            //登陆成功
            // 发送登陆后验证包
            byte[] peer0_1 = { /* Packet 90 */
                    0x3a, 0x6c, 0x15, 0x02, 0x00, 0xbf, 0x40, 0x00,
                    0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                    0x03, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 
            };
            sendDatas(peer0_1);


        }

        public void ReqDayKline(string filepath,string code,UInt16 reqID) 
        {
            byte[] sendData = PacketHelper.KlineReqPacketBuilder(filepath, code, DateTime.Now,reqID);
            sendDatas(sendData);
        }
        private void sendDatas(byte[] datas) 
        {
            lock (lockSend) 
            {
                stream.Write(datas, 0, datas.Length);
            }
        }


        private void ParseRspDayKline(byte[] packet)
        {
            List<KlineData> klineDatas = new List<KlineData>();
            if (packet.Length > 70)
            {
                var fileContent = packet;
                int mark = 70;
                while (true)
                {
                    KlineData klineData = new KlineData();

                    var date = BitConverter.ToUInt32(fileContent, mark);
                    mark += 4;

                    DateTimeOffset dateTimeOffset = DateTimeOffset.FromUnixTimeSeconds(date);

                    // 将 DateTimeOffset 对象转换为本地时间的 DateTime 对象
                    DateTime dateTime = dateTimeOffset.LocalDateTime;



                    // 获取日期部分，格式为 yyyyMMdd
                    string datePart = dateTime.ToString("yyyyMMdd");
                    klineData.date = datePart;
                    // 获取时间部分，格式为 HH:mm:ss
                    string timePart = dateTime.ToString("HH:mm:ss");
                    klineData.time = timePart;
                    //所有时间
                    string allTime = dateTime.ToString("yyyy-MM-dd HH:mm:ss");
                    klineData.allTime = allTime;





                    float open = BitConverter.ToSingle(fileContent, mark);
                    mark += 4;
                    klineData.open = open;


                    float close = BitConverter.ToSingle(fileContent, mark);
                    mark += 4;
                    klineData.close = close;

                    float high = BitConverter.ToSingle(fileContent, mark);
                    mark += 4;
                    klineData.high = high;

                    float low = BitConverter.ToSingle(fileContent, mark);
                    mark += 4;
                    klineData.low = low;

                    float cjl = BitConverter.ToSingle(fileContent, mark);
                    mark += 4;
                    klineData.cjl = cjl;

                    float ccl = BitConverter.ToSingle(fileContent, mark);
                    mark += 4;
                    klineData.ccl = ccl;

                    float avg = BitConverter.ToSingle(fileContent, mark);
                    mark += 4;
                    klineData.avg = avg;

                    //读取最后五位
                    byte[] bt = new byte[5];
                    Array.Copy(fileContent, mark, bt, 0, 5);
                    string str = Encoding.Default.GetString(bt);
                    mark += 5;


                    klineDatas.Add(klineData);
                    if (mark >= fileContent.Length)
                    {
                        break;
                    }

                }
            }
            
            int allKlineNum = BitConverter.ToInt16(packet, 45);
            int currKlineNum = BitConverter.ToInt16(packet, 49);
            ushort reqID = BitConverter.ToUInt16(packet, 38);
            OnRspDayKLine?.Invoke(allKlineNum, currKlineNum, klineDatas, reqID);
        }




        ~WHServer() 
        {
            stream.Close();
            stream.Dispose();
            client.Close();
            client.Dispose();
        }





        public void LoginOption(byte[] catchData)
        {
            byte[] loginData = {
                //0x3a, 0xe6, 0x02, 0x02, 0x08, 0x01, 0x00, 0x02,
                //0x00, 0x00, 0x67, 0x6c, 0xf2, 0x72, 0x00, 0x00,
                //0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                //0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                //0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                //0x00, 0x00, 0x35, 0x3b, 0xaf, 0x41, 0x48, 0x3d,
                //0x4d, 0x8e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                //0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                //0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                //0x00, 0x00, 0xe8, 0x03, 0x00, 0x00, 0x01, 0x00, //
                //0x00, 0x00, 0x8b, 0xc8, 0x5c, 0x00, 0x23, 0x00,
                //0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                //0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                //0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x35,
                //0x35, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                //0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                //0x30, 0x36, 0x33, 0x38, 0x63, 0x00, 0x3d, 0x4d,
                //0x79, 0x41, 0x44, 0x4e, 0x78, 0x45, 0x6a, 0x4d,
                //0x78, 0x45, 0x44, 0x4d, 0x77, 0x51, 0x6a, 0x00,//
                //0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                //0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x44,
                //0x30, 0x46, 0x34, 0x30, 0x35, 0x32, 0x30, 0x36,
                //0x33, 0x38, 0x43, 0x00, 0x00, 0x00, 0x00, 0x00,
                //0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                //0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                //0x00, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00,
                //0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                //0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                //0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                //0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                //0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                //0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //
                //0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x59, 0x4c,
                //0x58, 0x34, 0x53, 0x38, 0x30, 0x58, 0x2d, 0x20,
                //0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
                //0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
                //0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x7c,
                //0x62, 0x34, 0x37, 0x34, 0x31, 0x38, 0x37, 0x31,
                //0x7c, 0x44, 0x30, 0x46, 0x34, 0x30, 0x35, 0x32,
                //0x30, 0x36, 0x33, 0x38, 0x43, 0x00, 0x00, 0x00,
                //0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                //0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                //0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                //0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                //0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                //0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                //0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                //0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                //0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x42, 0x46,
                //0x45, 0x42, 0x46, 0x42, 0x46, 0x46, 0x30, 0x30,
                //0x30, 0x39, 0x30, 0x36, 0x41, 0x34, 0x7c, 0x34,
                //0x30, 0x32, 0x44, 0x46, 0x46, 0x30, 0x30, 0x2d,
                //0x32, 0x46, 0x39, 0x41, 0x2d, 0x31, 0x31, 0x45,
                //0x46, 0x2d, 0x42, 0x32, 0x33, 0x46, 0x2d, 0x45,
                //0x30, 0x33, 0x30, 0x34, 0x36, 0x42, 0x30, 0x32,
                //0x45, 0x30, 0x30, 0x7c, 0x35, 0x43, 0x44, 0x46,
                //0x5f, 0x42, 0x38, 0x30, 0x34, 0x5f, 0x34, 0x30,
                //0x39, 0x30, 0x5f, 0x30, 0x38, 0x41, 0x33, 0x2e,
                //0x7c, 0x44, 0x30, 0x46, 0x34, 0x30, 0x35, 0x32,
                //0x30, 0x36, 0x33, 0x38, 0x43, 0x00, 0x00, 0x00,
                //0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                //0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                //0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                //0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                //0x00, 0x00, 0x00, 0x00, 0x00, 0x00



                //0x3a, 0xe6, 0x02, 0x02, 0x08, 0x01, 0x00, 0x02,
                //0x00, 0x00, 0x67, 0x6c, 0xf2, 0x72, 0x00, 0x00,
                //0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                //0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                //0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                //0x00, 0x00, 0x35, 0x3b, 0xaf, 0x41, 0x48, 0x3d,
                //0x4d, 0x8e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                //0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                //0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                //0x00, 0x00, 0xe8, 0x03, 0x00, 0x00, 0x01, 0x00,
                //0x00, 0x00, 0x8b, 0xc8, 0x5c, 0x00, 0x23, 0x00,
                //0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                //0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                //0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x35,
                //0x35, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                //0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                //0x30, 0x36, 0x33, 0x38, 0x63, 0x00, 0x3d, 0x4d,
                //0x79, 0x41, 0x44, 0x4e, 0x78, 0x45, 0x6a, 0x4d,
                //0x78, 0x55, 0x6a, 0x4e, 0x77, 0x55, 0x6a, 0x00,
                //0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                //0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x44,
                //0x30, 0x46, 0x34, 0x30, 0x35, 0x32, 0x30, 0x36,
                //0x33, 0x38, 0x43, 0x00, 0x00, 0x00, 0x00, 0x00,
                //0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                //0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                //0x00, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00,
                //0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                //0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                //0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                //0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                //0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                //0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                //0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x59, 0x4c,
                //0x58, 0x34, 0x53, 0x38, 0x30, 0x58, 0x2d, 0x20,
                //0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
                //0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
                //0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x7c,
                //0x62, 0x34, 0x37, 0x34, 0x31, 0x38, 0x37, 0x31,
                //0x7c, 0x44, 0x30, 0x46, 0x34, 0x30, 0x35, 0x32,
                //0x30, 0x36, 0x33, 0x38, 0x43, 0x00, 0x00, 0x00,
                //0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                //0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                //0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                //0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                //0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                //0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                //0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                //0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                //0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x42, 0x46,
                //0x45, 0x42, 0x46, 0x42, 0x46, 0x46, 0x30, 0x30,
                //0x30, 0x39, 0x30, 0x36, 0x41, 0x34, 0x7c, 0x34,
                //0x30, 0x32, 0x44, 0x46, 0x46, 0x30, 0x30, 0x2d,
                //0x32, 0x46, 0x39, 0x41, 0x2d, 0x31, 0x31, 0x45,
                //0x46, 0x2d, 0x42, 0x32, 0x33, 0x46, 0x2d, 0x45,
                //0x30, 0x33, 0x30, 0x34, 0x36, 0x42, 0x30, 0x32,
                //0x45, 0x30, 0x30, 0x7c, 0x35, 0x43, 0x44, 0x46,
                //0x5f, 0x42, 0x38, 0x30, 0x34, 0x5f, 0x34, 0x30,
                //0x39, 0x30, 0x5f, 0x30, 0x38, 0x41, 0x33, 0x2e,
                //0x7c, 0x44, 0x30, 0x46, 0x34, 0x30, 0x35, 0x32,
                //0x30, 0x36, 0x33, 0x38, 0x43, 0x00, 0x00, 0x00,
                //0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                //0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                //0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                //0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                //0x00, 0x00, 0x00, 0x00, 0x00, 0x00


                0x3a, 0xe6, 0x02, 0x02, 0x08, 0x01, 0x00, 0x02,
                0x00, 0x00, 0x67, 0x6c, 0xf2, 0x72, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x35, 0x3b, 0xaf, 0x41, 0x48, 0x3d,
                0x4d, 0x8e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0xe8, 0x03, 0x00, 0x00, 0x01, 0x00,
                0x00, 0x00, 0x8b, 0xc8, 0x5c, 0x00, 0x23, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x35,
                0x35, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x30, 0x36, 0x33, 0x38, 0x63, 0x00, 0x3d, 0x4d,
                0x79, 0x41, 0x44, 0x4e, 0x78, 0x45, 0x6a, 0x4d,
                0x77, 0x6b, 0x54, 0x4f, 0x31, 0x56, 0x6a, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x44,
                0x30, 0x46, 0x34, 0x30, 0x35, 0x32, 0x30, 0x36,
                0x33, 0x38, 0x43, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x59, 0x4c,
                0x58, 0x34, 0x53, 0x38, 0x30, 0x58, 0x2d, 0x20,
                0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
                0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
                0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x7c,
                0x62, 0x34, 0x37, 0x34, 0x31, 0x38, 0x37, 0x31,
                0x7c, 0x44, 0x30, 0x46, 0x34, 0x30, 0x35, 0x32,
                0x30, 0x36, 0x33, 0x38, 0x43, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x42, 0x46,
                0x45, 0x42, 0x46, 0x42, 0x46, 0x46, 0x30, 0x30,
                0x30, 0x39, 0x30, 0x36, 0x41, 0x34, 0x7c, 0x34,
                0x30, 0x32, 0x44, 0x46, 0x46, 0x30, 0x30, 0x2d,
                0x32, 0x46, 0x39, 0x41, 0x2d, 0x31, 0x31, 0x45,
                0x46, 0x2d, 0x42, 0x32, 0x33, 0x46, 0x2d, 0x45,
                0x30, 0x33, 0x30, 0x34, 0x36, 0x42, 0x30, 0x32,
                0x45, 0x30, 0x30, 0x7c, 0x35, 0x43, 0x44, 0x46,
                0x5f, 0x42, 0x38, 0x30, 0x34, 0x5f, 0x34, 0x30,
                0x39, 0x30, 0x5f, 0x30, 0x38, 0x41, 0x33, 0x2e,
                0x7c, 0x44, 0x30, 0x46, 0x34, 0x30, 0x35, 0x32,
                0x30, 0x36, 0x33, 0x38, 0x43, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00

            };



           
            //var randomBytes = GenerateRandomString();

            //Array.Copy(catchData, 0, loginData, 134, 17);
            sendDatas(catchData);
        }


        public static byte[] GenerateRandomString(int length = 6)
        {
            const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
            StringBuilder result = new StringBuilder(length);
            Random random = new Random();

            for (int i = 0; i < length; i++)
            {
                result.Append(chars[random.Next(chars.Length)]);
            }
            return Encoding.UTF8.GetBytes(result.ToString());
        }












    }
}
